package com.example.demo.filters.inbound;

import com.example.demo.filters.endpoint.NotFoundEndpoint;
import com.netflix.zuul.context.SessionContext;
import com.netflix.zuul.filters.http.HttpInboundSyncFilter;
import com.netflix.zuul.message.http.HttpRequestMessage;
import com.netflix.zuul.netty.filter.ZuulEndPointRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author sleepforests
 * Created on 2019-06-27
 */
public class Routes extends HttpInboundSyncFilter {
    private static final Logger logger = LoggerFactory.getLogger(Routes.class);

    @Override
    public HttpRequestMessage apply(HttpRequestMessage request) {


        SessionContext context = request.getContext();
        context.setEndpoint(ZuulEndPointRunner.PROXY_ENDPOINT_FILTER_NAME);
        context.setRouteVIP("customRibbonAbc");

//        String path = request.getPath();
//        String host = request.getOriginalHost();
//
//
//        logger.info("path={}, host={}", path, host);
//
//        if (path.startsWith("/product")) {
//            context.setEndpoint(ZuulEndPointRunner.PROXY_ENDPOINT_FILTER_NAME);
//            context.setRouteVIP("customRibbonAbc");
//
//            return request;
//        }
//
//        if (path.startsWith("/xyz")) {
//            context.setEndpoint(ZuulEndPointRunner.PROXY_ENDPOINT_FILTER_NAME);
//            context.setRouteVIP("customRibbonXyz");
//
//            return request;
//        }

         return request;
    }


    @Override
    public int filterOrder() {
        return 0;
    }

    @Override
    public boolean shouldFilter(HttpRequestMessage msg) {
        return true;
    }
}
